/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Object;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author QuangHau
 */
public class Torrent {

    private String id;
    private String name;
    private float size;
    private ArrayList<Chunk> chunks;

    /**
     * @return the id
     */
    public String getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the size
     */
    public float getSize() {
        return size;
    }

    /**
     * @param size the size to set
     */
    public void setSize(float size) {
        this.size = size;
    }

    /**
     * @return the chunks
     */
    public ArrayList<Chunk> getChunks() {
        return chunks;
    }

    /**
     * @param chunks the chunks to set
     */
    public void setChunks(ArrayList<Chunk> chunks) {
        this.chunks = chunks;
    }

    public Torrent() {
        this.chunks = null;
        this.id = null;
        this.name = null;
        this.size = 0;
    }
    
    public Torrent( String fileID, String fileName, float fileSize, ArrayList<Chunk> fileChunk) {
        this.chunks = fileChunk;
        this.id = fileID;
        this.name = fileName;
        this.size = fileSize;
    }

    public Torrent(File file) {
        try (ObjectInputStream inStream = new ObjectInputStream(
                                                  new FileInputStream(file))) 
        {
            this.id = (String)inStream.readObject();
            this.name = (String)inStream.readObject();
            this.size = (int)inStream.readObject();
            this.chunks = (ArrayList<Chunk>)inStream.readObject();
            inStream.close();
        } catch (IOException | ClassNotFoundException ex) {
            Logger.getLogger(Torrent.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
